﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CXJ.Interface;

namespace CXJ.Libiary
{
    public  class CacheManger
    {
        private static ICache icache;
        private static object lockobj = new object();

        /// <summary>
        /// 缓存管理器的实例
        /// </summary>
        public static ICache Instance
        {
            get
            {
                if (icache == null)
                {
                    lock (lockobj)
                    {
                        if (icache == null)
                        {
                            icache = CacheFactory();
                        }
                    }
                }
                return icache;
            }
        }

        public static ICache CacheFactory()
        {
            System.Web.HttpContext currentContext = System.Web.HttpContext.Current;
            if (currentContext == null)
            {
                return new Cache.ContextCache();
            }
            else
            {
                return new Cache.WebCache();
            }
        }
    }
}
